Skip to content

module: fix extensionless entry with explicit type=commonjs#61600

Merged
nodejs-github-bot merged 1 commit intonodejs:mainfrom
inoway46:fix-extensionless-type-commonjs-esm
Feb 16, 2026
Merged

module: fix extensionless entry with explicit type=commonjs#61600
nodejs-github-bot merged 1 commit intonodejs:mainfrom
inoway46:fix-extensionless-type-commonjs-esm

Conversation

@inoway46
Copy link
Contributor

@inoway46 inoway46 commented Jan 31, 2026

When an extensionless entry point contains ESM syntax but is in a package with "type": "commonjs" in package.json, the module would silently exit with code 0 without executing or showing any error. This happened because extensionless files skip the .js suffix check in the CJS loader, so the explicit type: commonjs was not being enforced, allowing ESM syntax to be silently delegated to ESM loading which never completed before the process exited.

This change ensures the CJS loader treats extensionless entry points as commonjs when type is explicitly set to "commonjs" in package.json, forcing ESM syntax to surface as a SyntaxError instead of silently exiting.

Fixes: #61104

Related: #61171 (alternative approach)

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Jan 31, 2026
@inoway46 inoway46 marked this pull request as ready for review January 31, 2026 15:45
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, a couple of comments, otherwise this looks good.

@inoway46 inoway46 requested a review from joyeecheung February 1, 2026 04:06
@inoway46 inoway46 requested a review from joyeecheung February 1, 2026 17:12
@inoway46 inoway46 requested a review from joyeecheung February 6, 2026 16:17
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 7, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 7, 2026
@nodejs-github-bot
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.74%. Comparing base (f6464c5) to head (79d60d5).
⚠️ Report is 123 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61600      +/-   ##
==========================================
- Coverage   89.76%   89.74%   -0.03%     
==========================================
  Files         673      675       +2     
  Lines      203944   204538     +594     
  Branches    39191    39307     +116     
==========================================
+ Hits       183080   183553     +473     
- Misses      13194    13297     +103     
- Partials     7670     7688      +18     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 98.36% <100.00%> (+0.19%) ⬆️

... and 63 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@inoway46
Copy link
Contributor Author

inoway46 commented Feb 7, 2026

Thanks for the approval.
I pushed a small lint follow-up: I added require('../common') at the top of test/es-module/test-extensionless-esm-type-commonjs.js to satisfy the required module ordering rules.

I also verified make lint-js locally for the changed JS files.
Could you please rerun CI if needed? Thank you.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 8, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 8, 2026
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 8, 2026
@joyeecheung joyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 8, 2026
@joyeecheung
Copy link
Member

@inoway46 Can you squash the commits? I don't think they would pass the test individually.

@inoway46 inoway46 force-pushed the fix-extensionless-type-commonjs-esm branch from 601e4c5 to 79d60d5 Compare February 9, 2026 01:55
@inoway46
Copy link
Contributor Author

inoway46 commented Feb 9, 2026

I squashed the commits and force-pushed the branch.
The PR now has a single commit: 79d60d5.
Please let me know if you'd like any further changes.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 11, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 11, 2026
@nodejs-github-bot
Copy link
Collaborator

@inoway46
Copy link
Contributor Author

Friendly ping — this looks ready to land (CI is green and approvals are in place).
Please let me know if there’s anything else I should address from my side.

@Qard Qard added request-ci Add this label to start a Jenkins CI on a PR. commit-queue Add this label to land a pull request using GitHub Actions. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Feb 16, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 16, 2026
@nodejs-github-bot nodejs-github-bot merged commit 4f13746 into nodejs:main Feb 16, 2026
70 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 4f13746

aduh95 pushed a commit that referenced this pull request Feb 19, 2026
PR-URL: #61600
Fixes: #61104
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With "type": "commonjs", #!/usr/bin/env node file does not execute but returns success and no error messages when the file is ESM

7 participants

Comments